<div id="add-school-dialog">
    <form id="add-school-form">
        <div class="input-group">
            <label for="school-title" class="input-group-addon">学校名称</label>
            <input type="text" name="school_name" id="school-name" class="form-control" maxlength="50" required="required" placeholder="请填写学校名称"/>
        </div>
        <div class="left-right-side">
            <div class="input-group left-side">
                <label for="school-country" class="input-group-addon">国家</label>
                <input type="text" id="school-country" name="school_country" class="form-control" maxlength="20" placeholder="请输入所在国家"/>
            </div>
            <div class="input-group right-side">
                <label for="school-province" class="input-group-addon">省份</label>
                <input type="text" id="school-province" name="school_province" class="form-control" maxlength="20" placeholder="请输入所在省份"/>
            </div>
        </div>
        <div class="left-right-side">
            <div class="input-group left-side">
                <label for="school-city" class="input-group-addon">城市</label>
                <input type="text" id="school-city" name="school_city" class="form-control" maxlength="20" placeholder="请输入所在城市"/>
            </div>
            <div class="input-group right-side">
                <label for="school-region" class="input-group-addon">区域</label>
                <input type="text" id="school-region" name="school_region" class="form-control" maxlength="20" placeholder="请输入所在区域"/>
            </div>
        </div>
        <div class="input-group">
            <label for="school-address" class="input-group-addon">详细地址</label>
            <input type="text" id="school-address" name="school_address" class="form-control" maxlength="20" placeholder="请输入详细地址"/>
        </div>
        <div class="input-group">
            <input type="submit" class="form-control" value="确认添加"/>
        </div>
    </form>
</div>


<script>
    $(function () {
        $("#add-school-form").validate({
            submitHandler: function (form) {
                $.ajax({
                    url: '<?php echo base_url('api/addSchool');?>',
                    type: 'post',
                    data: $(form).serialize(),
                    beforeSend: function () {
                        showProgressNoty();
                    },
                    complete: function () {
                        closeProgressNoty();
                    },
                    success: function (jsonrsp) {
                        try {
                            var rsp = $.parseJSON(jsonrsp);
                            noty({type: rsp.type, text: rsp.message, callback: {
                                afterClose: function () {
                                    switch (rsp.type) {
                                        case 'success':
                                            location.reload();
                                            break;
                                        default:
                                            break;
                                    }
                                }
                            }});
                        } catch (ex) {
                            noty({type: 'error', text: '发生内部错误，请联系管理员'});
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        console.error(XMLHttpRequest, textStatus, errorThrown);
                        noty({type: 'error', text: '发生内部错误，请联系管理员'});
                    }
                });
            }
        });

    });
</script>